package com.hwadee.teachingprocessmanagementsystem.service.base.impl;

import com.hwadee.teachingprocessmanagementsystem.entity.Classes;
import com.hwadee.teachingprocessmanagementsystem.dao.ClassesDao;
import com.hwadee.teachingprocessmanagementsystem.service.base.ClassesService;
import jakarta.annotation.Resource;
import org.springframework.stereotype.Service;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.PageImpl;
import org.springframework.data.domain.PageRequest;


/**
 * 班级表(Classes)表服务实现类
 *
 * @author makejava
 * @since 2024-07-11 14:23:11
 */
@Service("classesService")
public class ClassesServiceImpl implements ClassesService {
    @Resource
    private ClassesDao classesDao;

    /**
     * 通过ID查询单条数据
     *
     * @param classId 主键
     * @return 实例对象
     */
    @Override
    public Classes queryById(Integer classId) {
        return this.classesDao.queryById(classId);
    }

    /**
     * 分页查询
     *
     * @param classes 筛选条件
     * @param pageRequest      分页对象
     * @return 查询结果
     */
    @Override
    public Page<Classes> queryByPage(Classes classes, PageRequest pageRequest) {
        long total = this.classesDao.count(classes);
        return new PageImpl<>(this.classesDao.queryAllByLimit(classes, pageRequest), pageRequest, total);
    }

    /**
     * 新增数据
     *
     * @param classes 实例对象
     * @return 实例对象
     */
    @Override
    public Classes insert(Classes classes) {
        this.classesDao.insert(classes);
        return classes;
    }

    /**
     * 修改数据
     *
     * @param classes 实例对象
     * @return 实例对象
     */
    @Override
    public Classes update(Classes classes) {
        this.classesDao.update(classes);
        return this.queryById(classes.getClassId());
    }

    /**
     * 通过主键删除数据
     *
     * @param classId 主键
     * @return 是否成功
     */
    @Override
    public boolean deleteById(Integer classId) {
        return this.classesDao.deleteById(classId) > 0;
    }
}
